package eerbaar.v2.pattern.client.internal.readers;

import eerbaar.game.IGame;
import eerbaar.memory.IMemory;
import eerbaar.message.lib.NotifyPetAtEdgeMsg;
import eerbaar.persona.IPersona;
import eerbaar.shared.message.IMessageReader;
import eerbaar.shared.message.Message;
import eerbaar.v2.app.GameHelper;
import eerbaar.v2.pattern.client.internal.teach.TeachingCommand;

public class PetAtEdgeMsgReader implements IMessageReader {

    private final TeachingCommand cmd;

    public PetAtEdgeMsgReader(TeachingCommand cmd) {
        this.cmd = cmd;
    }

    @Override
    public boolean read(Message msg) {

        if (!(msg instanceof NotifyPetAtEdgeMsg)) {
            return false;
        }

        IGame game = GameHelper.getGame();
        if (game == null) {
            return false;
        }
        IPersona pet = game.getPersona("pet");

        IMemory memory = pet.getHead().getBrain().getMemory();

        memory.addEvent("edge", "wall");

        if (this.cmd.isTeaching()) {
            this.cmd.getBody().stopTeaching();
        }

        return false;
    }

}
